package com.turkcell.dv.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;

import com.turkcell.dv.model.ProcessEndpointDOM;

import org.hibernate.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
@Transactional(readOnly = true)
public class ProcessEndpointDAOImpl implements ProcessEndpointDAO{

	private static final Logger logger = LoggerFactory.getLogger(ProcessEndpointDAOImpl.class);
	 
	@Autowired private SessionFactory sessionFactory;
    
    public void setSessionFactory(SessionFactory sf){
        this.sessionFactory = sf;
    }

	@SuppressWarnings("unchecked")
	@Override
	public List<ProcessEndpointDOM> listAllEndpoints() {
        Session session = this.sessionFactory.getCurrentSession();
        List<ProcessEndpointDOM> ProcessEndpointList = session.createQuery("from ProcessEndpointDOM").list();
        for(ProcessEndpointDOM pe : ProcessEndpointList){
            logger.info("ProcessEndpoint List::" + pe);
        }
        return ProcessEndpointList;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ProcessEndpointDOM> listEndpointsByProcessId(long processId) {
		Session session = this.sessionFactory.getCurrentSession();
		Query query = session.createQuery("from ProcessEndpointDOM PE WHERE PE.processId = :processId");
		query.setParameter("processId", processId);
		List<ProcessEndpointDOM> resultSet = query.list();
		for (ProcessEndpointDOM u : resultSet) {
			logger.info("User List::" + u);
		}
		return resultSet;
	}

}
